home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14642
/
14642.xpi
/
chrome
/
content
/
settings.js
< prev
next >
Wrap
Text File
|
2009-10-15
|
26KB
|
581 lines
/* Copyright 2008, Boomtango.com. All Rights Reserved. */
/* settings.js
* Responsible for updating settings fields
*/
Components.utils.import("resource://boomtango/app.js");
Components.utils.import("resource://boomtango/storage.js");
var mgr = {
panes: {
// general tab
general : {
NUMPERPAGE : [ 10, 25, 50, 100 ],
ITEMSPERCAT : [ 5, 10, 25 ],
YEAR: 60 * 24 * 365,
TABDELAY : [ 0, 5, 15, 60, 60 * 24 * 365 ],
VIEWS : [ 'category', 'calendar', 'piechart', 'thumbnail'],
DURS : [ 'hour', 'day', 'week', 'month'],
onLoad: function(){
var menu = document.getElementById("numPerPage");
var len = this.NUMPERPAGE.length;
var curr = boomtangoApp.searchItemsPerPage;
for(var x = 0; x < len; x++){
var num = this.NUMPERPAGE[x];
menu.appendItem(num);
if(num == curr){
menu.selectedIndex = x;
}
}
var menu = document.getElementById("itemsPerCat");
var len = this.ITEMSPERCAT.length;
var curr = boomtangoApp.glanceItemsPerPage;
for(var x = 0; x < len; x++){
var num = this.ITEMSPERCAT[x];
menu.appendItem(num);
if(num == curr){
menu.selectedIndex = x;
}
}
var menu = document.getElementById("defaultView");
var len = this.VIEWS.length;
var curr = boomtangoApp.historyView;
for(var x = 0; x < len; x++){
var id = this.VIEWS[x];
menu.appendItem(boomtangoApp.getString('view.'+id));
if(id == curr){
menu.selectedIndex = x;
}
}
var menu = document.getElementById("defaultDur");
var len = this.VIEWS.length;
var curr = boomtangoApp.historyDur;
for(var x = 0; x < len; x++){
var id = this.DURS[x];
menu.appendItem(boomtangoApp.getString('dur.'+id));
if(id == curr){
menu.selectedIndex = x;
}
}
var menu = document.getElementById("tabDelay");
var len = this.TABDELAY.length;
var curr = boomtangoApp.tabChangeTime;
for(var x = 0; x < len; x++){
var num = this.TABDELAY[x];
var label = num.toString();
if(num == this.YEAR){
label = boomtangoApp.getString("settings.never");
}
menu.appendItem(label);
if(num == curr){
menu.selectedIndex = x;
}
}
document.getElementById("btversion").
setAttribute("value",
boomtangoApp.getString("settings.version",
boomtangoApp.ext_version));
document.getElementById("dbversion").
setAttribute("value",
boomtangoApp.getString("settings.dbversion",
boomtangoApp.dbversion));
document.getElementById("uselog").checked = boomtangoApp.uselog;
document.getElementById("usethumb").checked = boomtangoApp.usethumb;
},
onDefaultView: function(){
var menu = document.getElementById("defaultView");
boomtangoApp.historyView = this.VIEWS[menu.selectedIndex];
},
onDefaultDur: function(){
var menu = document.getElementById("defaultDur");
boomtangoApp.historyDur = this.DURS[menu.selectedIndex];
},
onItemsPerCatChange: function(){
var menu = document.getElementById("itemsPerCat");
boomtangoApp.glanceItemsPerPage = this.ITEMSPERCAT[menu.selectedIndex];
},
onPerPageChange: function(){
var menu = document.getElementById("numPerPage");
boomtangoApp.searchItemsPerPage = this.NUMPERPAGE[menu.selectedIndex];
},
onTabDelayChange: function(){
var menu = document.getElementById("tabDelay");
boomtangoApp.tabChangeTime = this.TABDELAY[menu.selectedIndex];
},
onThumbClick: function(){
boomtangoApp.usethumb = !boomtangoApp.usethumb;
},
onLogClick: function(){
boomtangoApp.uselog = !boomtangoApp.uselog;
},
onShowLog: function(){
boomtangoApp.showLogFile();
},
onOK: function() { return true;},
onCancel: function() {}
},
// storage tab
storage : {
onLoad: function(){
var el = document.getElementById("deleteHistoryButton");
var self = this;
el.addEventListener(
"click",
function(e){
if(e.ctrlKey){
e.preventDefault();
self.onDeleteAll();
} else {
self.onDeleteHistory();
}
},
true
);
},
onOK: function() { return true;},
onCancel: function() {},
onDeleteThumbs: function() {
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var result = prompt.confirm(
window,
boomtangoApp.getString("settings.thumbprompt.title"),
boomtangoApp.getString("settings.thumbprompt.text")
);
if (result) {
boomtangoStorage.deleteAllThumb();
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var observer = Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observer.notifyObservers(null, "boomtango-refreshviews", "");
prompt.alert(window, "Boomtango", boomtangoApp.getString("settings.success.thumbdelete"));
}
},
onDeleteAll: function() {
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var result = prompt.confirm(
window,
boomtangoApp.getString("settings.historyall.title"),
boomtangoApp.getString("settings.historyall.text")
);
if (result) {
boomtangoApp.killBTData = true;
Components.classes["@mozilla.org/toolkit/app-startup;1"].
getService(Components.interfaces.nsIAppStartup).
quit(
Components.interfaces.nsIAppStartup.eAttemptQuit |
Components.interfaces.nsIAppStartup.eRestart
);
}
},
onDeleteHistory: function() {
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var result = prompt.confirm(
window,
boomtangoApp.getString("settings.historyprompt.title"),
boomtangoApp.getString("settings.historyprompt.text")
);
if (result) {
boomtangoStorage.deleteAllTrackers();
var observer = Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observer.notifyObservers(null, "boomtango-refreshviews", "");
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
prompt.alert(window, "Boomtango", boomtangoApp.getString("settings.success.historydelete"));
}
},
onChooseBackup: function() {
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(Components.interfaces.nsIFilePicker);
fp.defaultString = "backup.btd";
fp.init(window, "Boomtango", fp.modeSave);
fp.appendFilter("Boomtango", "*.btd");
var rv = fp.show();
if (rv == fp.returnOK || rv == fp.returnReplace) {
var textbox = document.getElementById("backup_textbox");
textbox.value = fp.file.path;
var button = document.getElementById("backup_button");
button.disabled = false;
}
},
onBackupInput: function(input) {
boomtangoApp.log("onBackupInput: " + input.value);
document.getElementById("backup_button").disabled = !input.value;
},
onBackup: function() {
var textbox = document.getElementById("backup_textbox");
// TODO: Need to process errors
var rv = boomtangoStorage.backupToFile(textbox.value);
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
prompt.alert(window, "Boomtango", boomtangoApp.getString(rv?"settings.success.backup":"settings.failure.backup"));
},
onChooseRestore: function(){
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(Components.interfaces.nsIFilePicker);
fp.init(window, "Boomtango", fp.modeOpen);
fp.appendFilter("Boomtango", "*.btd");
var rv = fp.show();
if (rv == fp.returnOK || rv == fp.returnReplace) {
var textbox = document.getElementById("restore_textbox");
textbox.value = fp.file.path;
var button = document.getElementById("restore_button");
button.disabled = false;
}
},
onRestoreInput: function(input) {
document.getElementById("restore_button").disabled = !input.value;
},
onRestore: function() {
var textbox = document.getElementById("restore_textbox");
// TODO: Need to process errors
var rv = boomtangoStorage.restoreFromFile(textbox.value);
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
prompt.alert(window, "Boomtango",
boomtangoApp.getString(rv?"settings.success.restore":"settings.failure.restore"));
var observer = Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces..nsIObserverService);
observer.notifyObservers(null, "boomtango-refreshviews", "");
}
},
// blacklist tab
blacklist : {
onLoad: function(){
var addresses = boomtangoApp.getBlacklist();
var list = document.getElementById("blacklist_list");
for(var x in addresses){
if(addresses.hasOwnProperty(x) && x != "web"){
list.appendItem(addresses[x], x);
}
}
list.selectedIndex = 0;
document.getElementById("address_remove").disabled = !list.getRowCount();
document.getElementById("address_remove_all").disabled = !list.getRowCount();
},
onAddressInput: function(input) {
document.getElementById("address_block").disabled = !input.value;
},
onAddressKeyPress: function (aEvent)
{
if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN)
document.getElementById("address_block").click();
},
onAddressBlock: function() {
var textbox = document.getElementById("address");
var host = textbox.value.replace(/^\s*([-\w]*:\/+)?/, ""); // trim any leading space and scheme
var addresses = boomtangoApp.getBlacklist();
for(var x in addresses){
if(addresses[x] == host){
return;
}
}
//var host = textbox.value;
boomtangoApp.addBlacklistData(host, false);
var list = document.getElementById("blacklist_list");
list.appendItem(host, host);
document.getElementById("address_remove").disabled = !list.getRowCount();
document.getElementById("address_remove_all").disabled = !list.getRowCount();
},
onAddressRemove: function(){
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var list = document.getElementById("blacklist_list");
var addresses = boomtangoApp.getBlacklist();
var item = list.getItemAtIndex(list.selectedIndex);
var data = addresses[item.value];
boomtangoApp.deleteBlacklistData(data);
var oldIndex = list.selectedIndex;
list.removeItemAt(list.selectedIndex);
list.selectedIndex = (oldIndex < list.getRowCount())?oldIndex:(oldIndex - 1);
document.getElementById("address_remove").disabled = !list.getRowCount();
document.getElementById("address_remove_all").disabled = !list.getRowCount();
},
onAddressRemoveAll: function(){
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var list = document.getElementById("blacklist_list");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
var data = types[item.value];
var result = prompt.confirm(
window,
boomtangoApp.getString("settings.removealladdress.title"),
boomtangoApp.getString("settings.removealladdress.text")
);
if (result) {
boomtangoApp.deleteAllBlacklist();
for (i = list.getRowCount() - 1;i >= 0; i--) {
list.removeItemAt(i);
}
}
document.getElementById("address_remove").disabled = !list.getRowCount();
document.getElementById("address_remove_all").disabled = !list.getRowCount();
},
onOK: function() { return true;},
onCancel: function() {}
},
// tracking tab
tracking : {
onLoad: function(){
var types = boomtangoApp.tracker.types;
var list = document.getElementById("tracker");
for(var x in types){
if(types.hasOwnProperty(x) && x != "web"){
list.appendItem(types[x].name, x);
}
}
list.selectedIndex = 0;
},
onListSelect: function(){
var list = document.getElementById("tracker");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
if(!item){
return;
}
var data = types[item.value];
document.getElementById("tracker_current")
.setAttribute("label", data.name);
document.getElementById("tracker_enable").
setAttribute("checked",
boomtangoApp.getTrackerEnabled(item.value));
document.getElementById("tracker_color").color =
boomtangoApp.getTrackerColor(item.value);
document.getElementById("tracker_resetcolor").
setAttribute("hidden",
boomtangoApp.getTrackerColor(item.value) ==
data.color);
var desc = document.getElementById("tracker_desc");
while(desc.firstChild){
desc.removeChild(desc.firstChild);
}
desc.appendChild(document.createTextNode(data.description));
document.getElementById("tracker_delete").
setAttribute("disabled", data.isInternal);
document.getElementById("tracker_advanced").
setAttribute("hidden", !data.onAdvancedLoad);
document.getElementById("tracker_version").
setAttribute("hidden", !data.plugin_version);
if(data.plugin_version){
document.getElementById("plugin_version").
setAttribute("value", data.plugin_version);
}
document.getElementById("plugin_url").
setAttribute("hidden", !data.plugin_url);
if(data.plugin_url){
document.getElementById("plugin_url").
setAttribute("href", data.plugin_url + "?id="+data.id.split('.').slice(1).join('.') + "&version="+data.plugin_version);
}
window.sizeToContent();
},
onAdvanced: function(){
var list = document.getElementById("tracker");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
window.openDialog("chrome://boomtango/content/pluginAdvanced.xul", "",
"chrome, dialog, modal", types[item.value]).focus();
},
onEnable: function(){
var enableit = !document.getElementById("tracker_enable").checked;
var list = document.getElementById("tracker");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
boomtangoApp.tracker.enableTracker(item.value, enableit);
},
onColor: function(){
var color = document.getElementById('tracker_color').color;
var list = document.getElementById("tracker");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
boomtangoApp.setTrackerColor(item.value, color);
document.getElementById("tracker_resetcolor").
setAttribute("hidden",
boomtangoApp.getTrackerColor(item.value) ==
types[item.value].color);
},
onResetColor: function(){
var list = document.getElementById("tracker");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
boomtangoApp.resetTrackerColor(item.value);
document.getElementById('tracker_color').color = types[item.value].color;
document.getElementById("tracker_resetcolor").
setAttribute("hidden","true");
},
onCreate:function(){
var retVal = { type: null };
window.openDialog("chrome://boomtango/content/createCategory.xul", "",
"chrome, dialog, modal", retVal).focus();
if(retVal.type){
var types = boomtangoApp.tracker.types;
var list = document.getElementById("tracker");
list.selectItem(list.appendItem(types[retVal.type].name, retVal.type));
}
},
onImport: function(){
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var list = document.getElementById("tracker");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
var data = types[item.value];
var result = prompt.confirm(
window,
boomtangoApp.getString("settings.importtracker.title"),
boomtangoApp.getString("settings.importtracker.text")
);
if (result) {
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(Components.interfaces.nsIFilePicker);
fp.init(window, "Boomtango", fp.modeOpen);
fp.appendFilter("Boomtango", "*.bct");
var rv = fp.show();
if (rv == fp.returnOK || rv == fp.returnReplace) {
var type = boomtangoApp.tracker.importTracker(fp.file);
if(type != '????'){
var types = boomtangoApp.tracker.types;
var list = document.getElementById("tracker");
list.selectItem(list.appendItem(types[type].name, type));
}
}
}
},
onDelete: function(){
var prompt = Components.
classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var list = document.getElementById("tracker");
var types = boomtangoApp.tracker.types;
var item = list.getItemAtIndex(list.selectedIndex);
var data = types[item.value];
var result = prompt.confirm(
window,
boomtangoApp.getString("settings.deletetracker.title"),
boomtangoApp.getString("settings.deletetracker.text", data.name)
);
if (result) {
boomtangoApp.tracker.deleteTracker(item.value);
var oldIndex = list.selectedIndex;
list.removeItemAt(list.selectedIndex);
list.selectedIndex = oldIndex - 1;
}
},
onOK: function() { return true;},
onCancel: function() {}
},
},
onLoad: function(){
var panes = this.panes;
for(var x in panes){
if(panes.hasOwnProperty(x)){
panes[x].onLoad();
}
}
// prefwindow on mac doesn't resize properly
if (navigator.platform.toLowerCase().indexOf('mac') > -1){
window.addEventListener(
"resize",
function(){
window.setTimeout(
function(){
window.sizeToContent();
},
0
);
},
false
);
}
},
onCancel: function(){
var panes = this.panes;
for(var x in panes){
if(panes.hasOwnProperty(x)){
panes[x].onCancel();
}
}
},
onOK: function(){
var panes = this.panes;
for(var x in panes){
if(panes.hasOwnProperty(x)){
if(!panes[x].onOK()){
return false;
}
}
}
return true;
}
};